#include <stdio.h>
#include <string.h>

#define MAXLINES 5000 /* max #lines to be sorted */
#define MAXLEN 1000 /* max length of any input line */

char *lineptr[MAXLINES]; /* pointers to text lines */

int readlines(char *lineptr[], int maxlines); //defined
void writelines(char *lineptr[], int nlines); //defined
void qsort(char *lineptr[], int left, int right);

/* sort input lines */
int main()
{
    int nlines; /* number of input lines read */

    if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
        qsort(lineptr, 0, nlines-1);
        writelines(lineptr, nlines);
        return 0;
    } else {
        printf("error: input too big to sort\n");
        return 1;
    }
}

/* 请在这里填写答案 */
void swap(char *v[],int i,int j)
{
    char *tmp;
    tmp=v[i];
    v[i]=v[j];
    v[j]=tmp;
    
}
void qsort(char *v[], int left, int right)
{
    if(left>=right)
        return;
    swap(v,left,(left+right)>>1);
    int last=left;
    for(int i=left+1;i<=right;++i)
        if(strcmp(v[i],v[left])<0)
            swap(v,++last,i);
    swap(v,left,last);
    qsort(v,left,last-1);
    qsort(v,last+1,right);
}
